﻿using System;
using System.Collections.Generic;
using System.Text;
using StackExchange.Redis;
using Microsoft.Extensions.Options;

namespace DotnetSpider.Agent
{
	public class RedisClient
	{
		private static Lazy<ConfigurationOptions> ConfigOptions = new Lazy<ConfigurationOptions>(() =>
		{ 
			 var connection = "192.168.3.202:6379,allowAdmin=true,connectTimeout=30000,syncTimeout=5000";

			return ConfigurationOptions.Parse(connection);
		});

		private static Lazy<ConnectionMultiplexer> Connection = new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(ConfigOptions.Value));

		private static ConnectionMultiplexer SafeConn
		{
			get
			{
				return Connection.Value;
			}
		}

		public static IDatabase Database
		{
			get
			{
				return SafeConn.GetDatabase();
			}
		}
	}

}
